package DAO;

import Entities.DoeBookEntity;
import Entities.UserEntity;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import java.util.ArrayList;
import java.util.List;


public class RecommendDao extends HibernateDaoSupport
{
    public List<DoeBookEntity> recommend(String user_name)
    {
        List<DoeBookEntity> resultList;

        //首先根据用户名获取用户对象，从而获取用户标签
        List<UserEntity> userList = (List<UserEntity>) this.getHibernateTemplate().find("from UserEntity u where u.userName=?",user_name);
        if(userList.size()!=1)
            return null;
        UserEntity ue = userList.get(0);

        //此处插入推荐算法
        resultList = (List<DoeBookEntity>) this.getHibernateTemplate().find("from DoeBookEntity d where d.pages='141'");

        return resultList;
    }

    //根据图书id列表返回图书列表
    public List<DoeBookEntity> bookListByIds(List<String> ids)
    {
        List<DoeBookEntity> bookEntities = new ArrayList<>();
        for (String id : ids)
        {
            bookEntities.add((DoeBookEntity) this.getHibernateTemplate().get(DoeBookEntity.class,id));
        }
        return bookEntities;
    }

}

